#include "Logbook.h"

int main(int argc, char** argv)
{
	// Encapsulation FTW!
	Logbook logbook;
	logbook.execute(argv);

	return 0;
}

#if 0
	// TODO - this assumes that the magical time function exists?
	bool time_fun = true;
	std::string date_today_computer_str;
	std::string date_today_str;
	int date_today;
	std::string year_today_str;
	int year_today;

#if 0
	// TODO - I do not see where we actually check if the time function is available
	// if function available, get today's date for currency computation and header
	char sdate[9];					
	_strdate_s( sdate );
	date_today_computer_str = sdate;
	date_today_str = date_today_computer_str.substr(0,2) + date_today_computer_str.substr(3,2);
	if (date_today_str.substr(0,1) == "0")
		date_today_str = date_today_str.substr(1,3);

	date_today = 100 * (util::string_to_int(date_today_computer_str.substr(0,2))) + util::string_to_int(date_today_computer_str.substr(3,2));
	year_today_str = "20" + date_today_computer_str.substr(6,2);
	year_today = 2000 + (util::string_to_int(date_today_computer_str.substr(6,2)));

	// if time function not available, last logged day and year substituted for today's date
	if (!time_fun)
	{
		date_today = date;
		date_today_str = date_str;
		year_today = year;
		year_today_str = year_str;
	}
	int date_last = date;
	std::string date_last_str = date_str;
	int year_last = year;
	std::string date_year_str = year_str;
	std::string date_good;
#endif

int begin_date = 0101;        // date/year select variable definitions
std::string begin_date_str;
int begin_year = 1900;
std::string begin_year_str;
int ending_date = 1231;
std::string ending_date_str;
int ending_year = 3000;     
std::string ending_year_str;
std::string date_range_inq;    
std::string plane_inq;
int plane_index_select;        // plane select variables
std::string plane_select;
std::string plane_model_select;
std::string plane_valid = "no";
std::string airport_inq;
int airport_index_select;    // airport select variables
std::string airport_select;
std::string airport_valid = "no";
std::vector < int > airport_candidates(50);
int airport_candidates_num;
int airport_list_select = -1;
std::string airport_list_select_str;

// find dates 90 days, 180 days, and one year prior to today's date

if (time_fun == "n")
{
	date_today = log[log.size() - 1].date();
	year_today = log[log.size() - 1].year();
}

int date_today_comp = date_today + (year_today % 4) * 10000;
int date_start_90;
int year_start_90;
int date_start_180;
int year_start_180;
int date_start_365;
int year_start_365;
int year_minus = 364;
int k = 364;
int leap_year = 0;
do
{
	++k;
} while(_dates[k] != date_today_comp);

date_start_90 = vec_dates[k - 89] % 10000;

if (vec_dates[k - 89]/10000 == vec_dates[k]/10000)
	year_start_90 = year_today;
else
	year_start_90 = year_today - 1;

date_start_180 = vec_dates[k - 179] % 10000;
if (vec_dates[k - 179] / 10000 == vec_dates[k]/10000)
	year_start_180 = year_today;
else
	year_start_180 = year_today - 1;

if (vec_dates[k] > 228 && vec_dates[k] < 10228)
	leap_year = 1;

date_start_365 = vec_dates[k - year_minus - leap_year] % 10000;
year_start_365 = year_today - 1;	



else if (!all_data_inq)
{          // closing bracket at 2104
    std::string date_select_inq;
	cout << endl;
	cout << "'a'  All dates" << endl;
	cout << "'3'  Last  90 days" << endl;
	cout << "'6'  Last 180 days" << endl;
	cout << "'t'  Last  12 months" << endl;
	cout << "'s'  Single calendar year" << endl;
	cout << "'r'  Range calendar years" << endl;
	cout << "'c'  Custom search" << endl << endl;
	cout << "Choose from the above options   [default = all dates]: ";

	do
	{
		cin.getline(entry, 50, '\n');
		date_range_inq = entry;
		if (date_range_inq == "")
			date_range_inq = "a";
		date_range_inq = util::all_lower(date_range_inq);
		if (date_range_inq != "s" && date_range_inq != "a" && date_range_inq != "c" && date_range_inq != "r" && date_range_inq != "t" && date_range_inq != "3" && date_range_inq != "6")
			cout << "Invalid input. Try again: ";
	} while(date_range_inq != "s" && date_range_inq != "a" && date_range_inq != "c" && date_range_inq != "r" && date_range_inq != "t" && date_range_inq != "3" && date_range_inq != "6");
if (date_range_inq == "a")
	date_range_inq = "n";
cout << endl;

if (date_range_inq == "s" || date_range_inq == "r")
{
	begin_date = 101;
	ending_date = 1231;
}
if (date_range_inq == "t")
{
	begin_date = date_start_365;
	begin_year = year_start_365;
	ending_date = 1231;
	ending_year = 3000;
}
if (date_range_inq == "3")
{
	begin_date = date_start_90;
	begin_year = year_start_90;
	ending_date = 1231;
	ending_year = 3000;
}
if (date_range_inq == "6")
{
	begin_date = date_start_180;
	begin_year = year_start_180;
	ending_date = 1231;
	ending_year = 3000;
}	
if (date_range_inq == "s" || date_range_inq == "r" || date_range_inq == "c")
{
    if (date_range_inq == "c")
	{
		cout << "Enter beginning date (MMDD) (0101 - 1231): ";
		date_good = "n";
		do
		{
			cin.getline(entry, 50, '\n');
			begin_date_str = entry;
		    begin_date = util::string_to_int(begin_date_str);
			for(int i = 1095; i < 1461; i++)
			{
				if (begin_date == vec_dates[i])
					date_good = "y";
			}
			if (date_good == "n")
				cout << "Invalid input. Try again:                  ";
		} while (date_good == "n");
		cout << endl;
	}

	if (date_range_inq == "s")
		cout << "Enter year (YYYY) (1950 - 2050):           ";
	else
		cout << "Enter beginning year (YYYY) (year > 1899): ";
    do
	{
		cin.getline(entry, 50, '\n');
		begin_year_str = entry;
		begin_year = util::string_to_int(begin_year_str);
		if (begin_year < 1900)
			cout << "Invalid input. Try again:                  ";
	} while (begin_year < 1900);
	cout << endl;
	if (date_range_inq == "s")
	{
		ending_year = begin_year;
		ending_year_str = begin_year_str;
	}
    else if (date_range_inq == "c")
	{    
		std::cout << "Enter ending date (MMDD) (0101 - 1231): ";
		date_good = "n";
		do
		{
			std::cin.getline(entry, 50, '\n');
			ending_date_str = entry;
			ending_date = util::string_to_int(ending_date_str);
			for(int i = 1095; i < 1461; i++)
			{
				if (ending_date == vec_dates[i])
					date_good = "y";
			}
			
			if (date_good == "n")
				std::cout << "Invalid input. Try again: ";
			}while (date_good == "n");
		std::cout << std::endl;
	}

    if (date_range_inq == "c" || date_range_inq == "r")
	{
	    std::cout << "Enter ending year (YYYY) (year > " << begin_year - 1 << "): ";
		do
		{
			std::cin.getline(entry, 50, '\n');
			ending_year_str = entry;
			ending_year = util::string_to_int(ending_year_str);
			if (ending_year < begin_year)
				std::cout << "Invalid input. Try again: ";
		} while (ending_year < begin_year);
		std::cout << std::endl;
		}
    }

// select one plane section

	std::cout << "AIRCRAFT SEARCH:" << std::endl;
	std::cout << "The aircraft must be in the database." << std::endl;
	std::cout << "Enter desired call letters   [default = all aircraft]: ";
	do
	{		
		std::cin.getline(entry, 50, '\n');
		plane_select = entry;
		if (plane_select == "")
		{
			plane_inq = "n";
			plane_valid = "yes";
		}
		else
		{
			plane_valid = "no";
			plane_inq = "y";
			plane_select = util::remove_leading_blanks(plane_select);
			plane_select = util::replace_comma(plane_select);
			plane_select = util::all_caps(plane_select);
			cout << endl;
            for (unsigned int plane_index = 0; plane_index < planes.size(); plane_index++)
			{
				if (plane_select == planes[plane_index].callNumber())
				{
					plane_valid = "yes";
					plane_model_select = planes[plane_index].model();
					plane_index_select = plane_index;
				}
			}
			if (plane_valid == "no")
				std::cout << "Invalid entry. Try again: ";
		}
	} while (plane_valid == "no");

	std::cout << std::endl;

//**** select one airport section

std::cout << "AIRPORT SEARCH:" << std::endl;
std::cout << "The airport must be in the database." << std::endl;
std::cout << "Enter airport ID or first 3 to 5 char of airport name" << std::endl;
std::cout << "                             [default = all airports]: ";
int used2;
do
{
	do	
	{
		std::cin.getline(entry, 50, '\n');
		airport_select = entry;
		if (airport_select == "")
		{
			airport_inq = "n";
			cout << endl;
		}
		else
		{
			airport_inq = "y";
			airport_valid = "no";
			airport_select = util::remove_leading_blanks(airport_select);
			airport_select = util::replace_comma(airport_select);
			cout << endl;
		}
		if ((airport_select.length() < 3 || airport_select.length() > 5) && airport_select != "")
			cout << "                             Invalid input. Try again: ";
	} while ((airport_select.length() < 3 || airport_select.length() > 5) && airport_select != "");

	if (airport_inq == "y")
	{
		airport_select = util::all_caps(airport_select);
		airport_candidates_num = -1;
		used2 = -1;
        for (unsigned int airport_index = 0; airport_index < airports.size(); airport_index++)
        {
			if (airport_select == airports[airport_index].id())
			{
				airport_candidates_num += 1;
				airport_candidates[airport_candidates_num] = airport_index;
				airport_valid = "yes";
				used2 = airport_index;
			}
		}
		for (unsigned int airport_index = 0; airport_index < airports.size(); airport_index++)
		{
			if (airport_select == util::all_caps(airports[airport_index].name().substr(0, airport_select.length())) && airport_index != used2)
			{
				airport_candidates_num += 1;
				airport_candidates[airport_candidates_num] = airport_index;
				airport_valid = "yes";
			}
		}
		
		if (airport_candidates_num > 0)
		{
			for (int can_index = 0; can_index <= airport_candidates_num; can_index ++)
			{
				cout << setw(2) << can_index + 1 << " " << airports[airport_candidates[can_index]].id() 
				<< util::string_print_spacer(airports[airport_candidates[can_index]].id(), 5) 
				<< airports[airport_candidates[can_index]].name() << " " 
				<< airports[airport_candidates[can_index]].suf() << endl;
			}
		}
		if (airport_valid == "no" && airport_inq != "n")
		cout << "Invalid entry. Try again: "; 
	}
} while (airport_valid == "no" && airport_inq != "n");
	
	if (airport_inq == "y")
	{
		if (airport_candidates_num == 0)
			airport_index_select = airport_candidates[0];
		if (airport_candidates_num > 0)
		{
	        cout << endl;
		    do
			{
				cout << "Enter number to select airport (1 to " << setw(2) << airport_candidates_num + 1 << ") ";	
				cin.getline(entry, 50, '\n');
				airport_list_select_str = entry;
				airport_list_select = util::string_to_int(airport_list_select_str);
				cout << endl;
			} while(airport_list_select < 1 || airport_list_select > airport_candidates_num + 1);  
			airport_index_select = airport_candidates[airport_list_select - 1];
		}  

		if (airport_valid == "yes")
			std::cout << "Selected airport: " << airports[airport_index_select].id() << "  " << airports[airport_index_select].name()
				 << ", " << airports[airport_index_select].suf() << endl << endl;
	}
}    //  if all_data = 'n' bracket from 1853            

std::cout << "Processing logbook data" << std::endl;        // variables to read line of logbook .cvs data 
std::string trips_type;                //  trips variables
std::string trips_longest_date;
double trips_longest = 0;    
int trips_longest_dep;
int trips_longest_des;
double trips_xc49_distance = 0;
double trips_xc49_flights = 0;
double trips_xc49_hours = 0;
double trips_xc50_distance = 0;
double trips_xc50_flights = 0;
double trips_xc50_hours = 0;
double xc_distance;        
std::vector < int > seq_airports;
std::vector < int > seq_plane;
std::vector < int > seq_select;
double total_local_flights = 0;
double total_local_hours = 0;
double student_total_hours = 0;
double rg_hours = 0;
double hp_hours = 0;
double tw_hours = 0;
double EST_total = 0;
double EST_dual = 0;
double EST_solo = 0;
double EST_pic = 0;
double EST_xc_dual = 0;
double EST_xc_solo = 0;
double EST_xc_pic = 0;
double EST_ifr = 0;
double EST_night_dual = 0;
double EST_night_land = 0;
double EST_night_land_pic = 0;
double EST_night_pic = 0;
double EST_sim_dual = 0;
double EST_gad_dual = 0;
double EST_sim = 0;

// finally the logbook.csv will be opened and processed
for(unsigned int i = 0; i < log.size(); i++)
{															// look for selected dates, plane or airport
    select_test = "good";
    if (log[i].year() < begin_year || (log[i].year() == begin_year && log[i].date() < begin_date) || log[i].year() > ending_year || (log[i].year() == ending_year && log[i].date() > ending_date))
        select_test = "bad";
    if (plane_inq == "y" && plane_index_select != log[i].getPlaneInd()) 
        select_test = "bad";
    if (airport_inq == "y" && (airport_index_select != log[i].getDepInd() && airport_index_select != log[i].getDesInd()))
        select_test = "bad";
    if (select_test == "good")
        {
		plane_index = log[i].getPlaneInd();
		dep_index = log[i].getDepInd();
		des_index = log[i].getDesInd();
		if (planes[plane_index].dayHours() == 0)
			seq_plane.push_back(plane_index);

		xc_distance = great_circle(airports[dep_index].getLatitude(), airports[dep_index].getLongitude(),
								   airports[des_index].getLatitude(), airports[des_index].getLongitude());
		if (xc_distance >= 50.0)
			xc = log[i].dayHours();
		else
			xc = 0;

		for (unsigned int j = 0; j < class_types.size(); j++)
			{
			if (planes[plane_index].type() == class_types[j].type())
				class_types[j].addLogEntry(log[i].dateStr(), log[i].dayHours());
			}
		for (unsigned int j = 0; j < class_models.size(); j++)
			{
			if (planes[plane_index].getModel() == class_models[j].getModel())
				class_models[j].addLogEntry(log[i].dateStr(), plane_index, log[i].dayHours(), log[i].nightHours(),
				log[i].ifr(), log[i].gad(), xc, log[i].cfi(), log[i].dual(),
				log[i].pic(), log[i].sic(), log[i].safety());
			}

		planes[0].addLogEntry(log[i].dateStr(), log[i].dayHours(), log[i].nightHours(),
		log[i].ifr(), log[i].gad(), xc, log[i].cfi(), log[i].dual(),
		log[i].pic(), log[i].sic(), log[i].safety());

		planes[plane_index].addLogEntry(log[i].dateStr(), log[i].dayHours(), log[i].nightHours(),
		log[i].ifr(), log[i].gad(), xc, log[i].cfi(), log[i].dual(),
		log[i].pic(), log[i].sic(), log[i].safety());

		if (planes[plane_index].getType() == "SEL" || planes[plane_index].getType() == "MEL" || 
			planes[plane_index].getType() == "SES" || planes[plane_index].getType() == "MES")
			{
			EST_total += log[i].dayHours();
			EST_dual += log[i].dual();
			EST_pic += log[i].pic();
			EST_ifr += log[i].ifr();
			EST_solo += log[i].dayHours() - log[i].dual() - log[i].sic() - log[i].safety();
			if (log[i].dual() > .5 && log[i].gad() > .5)
				EST_gad_dual += log[i].gad();
			if (xc_distance >= 50.0)
				{
				EST_xc_dual += log[i].dual();
				EST_xc_pic += log[i].pic();
				EST_xc_solo += log[i].dayHours() - log[i].dual() - log[i].sic() - log[i].safety();
				}
			if (log[i].nightHours() > .5)
				{
				EST_night_land += log[i].getNitLand();
				if (log[i].dual() > .5)
					EST_night_dual += log[i].nightHours();
				if (log[i].pic() > .5)
					{
					EST_night_land_pic += log[i].getNitLand();
					EST_night_pic += log[i].nightHours();
					}
				}
			}
		if (planes[plane_index].getType() == "SIM" && log[i].cfi() < .5)
			{
			EST_sim += log[i].dayHours();
			if (log[i].dual()>0)
				EST_sim_dual += log[i].dayHours();
			}

		if (log[i].getStudent() > 0)
			{
            students[log[i].getStudent() - 1].addStudentHours(log[i].dateStr(), log[i].cfi());
			student_total_hours += log[i].cfi();
			}

		if (planes[plane_index].getRg() == "RG")
			rg_hours += log[i].dayHours();
		if (planes[plane_index].getHp() == "HP")
			hp_hours += log[i].dayHours();
		if (planes[plane_index].getTw() == "TW")
			tw_hours += log[i].dayHours();

		if (airport_inq == "y" || plane_inq == "y")
			seq_select.push_back(i);

		if (dep_index == des_index)
			{
			if (airport_inq == "n" || (airport_inq == "y" && airport_index_select == dep_index))
				{
				total_local_flights += 1;
				total_local_hours += hours;
				if (airports[dep_index].getLocalHours() < .5 && airports[dep_index].getXcHours() < .5)
					seq_airports.push_back(dep_index);
				airports[des_index].addLocal (log[i].dateStr(), log[i].dayHours());
				}
			}
		else
		{
			if (airport_inq == "n" || (airport_inq == "y" && airport_index_select == dep_index))
				{		
				if (airports[dep_index].getLocalHours() < .5 && airports[dep_index].getXcHours() < .5)
					seq_airports.push_back(dep_index);
				airports[dep_index].addXc (log[i].dateStr(), log[i].dayHours());
				}
			if (airport_inq == "n" || (airport_inq == "y" && airport_index_select == des_index))
				{		
				if (airports[des_index].getLocalHours() < .5 && airports[des_index].getXcHours() < .5)
					seq_airports.push_back(des_index);
				airports[des_index].addXc (log[i].dateStr(), log[i].dayHours());
				}
		    if (airport_inq == "n" || (airport_inq == "y" && (airport_index_select == dep_index || airport_index_select == des_index)))
				{
				if (xc_distance > trips_longest)
					{
					trips_longest_date = log[i].dateStr();
			        trips_longest = xc_distance; 
					trips_longest_dep = dep_index;
					trips_longest_des = des_index;
				    }
				if (xc_distance >= 50)
				{
					trips_xc50_distance += xc_distance;
					trips_xc50_flights += 1;
					trips_xc50_hours += log[i].dayHours();
				}
				else
				{
					trips_xc49_distance += xc_distance;
					trips_xc49_flights += 1;
					trips_xc49_hours += log[i].dayHours();
				}
				trips_type = "new";
				for (unsigned int tr_fl = 0; tr_fl < class_trips.size(); tr_fl++)
				{
			        if (class_trips[tr_fl].getDep() == dep_index && class_trips[tr_fl].getDes() == des_index)
					{
						class_trips[tr_fl].addTrip(log[i].dateStr(), log[i].dayHours());
						trips_type = "exist";
					}
	                if (class_trips[tr_fl].getDep() == des_index && class_trips[tr_fl].getDes() == dep_index)
					{
						class_trips[tr_fl].addRevTrip(log[i].dateStr(), log[i].dayHours());
						trips_type = "rev";
					}
				}
	            if (trips_type == "new")
				{
					trip_tmp.setTrip (log[i].dateStr(), dep_index, des_index, xc_distance, log[i].dayHours());
					class_trips.push_back(trip_tmp);
				}
			}
 		}
        }                // good / bad selection  
	 } // end of log
logbooks.close();

//**** processing data for flylog, mostly detailed airplane data, output
    
std::cout << "           flylog" << std::endl;

//****  flylog output  this is the same header in flylog, trips and the two sequence files
ofstream flylog_output;
flylog_output.open("output_logbook.txt");
if (time_fun == "y" || time_fun == "y")
	flylog_output << "Today's date         : ";
else
	flylog_output << "Last flight logged   : ";
flylog_output << int_to_string_date_format(year_today, date_today) << endl;

flylog_output << "Flight dates searched: ";
if (date_range_inq == "n")
    flylog_output << "total logbook"  << endl;

if (date_range_inq == "3")
	{
	flylog_output << int_to_string_date_format(year_start_90, date_start_90) << " thru ";
	flylog_output << int_to_string_date_format(year_today, date_today) << "   90-day search" << endl;
	}
if (date_range_inq == "6")
	{
	flylog_output << int_to_string_date_format(year_start_180, date_start_180) << " thru ";
	flylog_output << int_to_string_date_format(year_today, date_today) << "  180-day search" << endl;
	}
if (date_range_inq == "t")
	{
	flylog_output << int_to_string_date_format(year_start_365, date_start_365) << " thru ";
	flylog_output << int_to_string_date_format(year_today, date_today) << "  365(6)-day search" << endl;
	}
if (date_range_inq == "s")
    flylog_output << "The year " << begin_year_str << endl;
if (date_range_inq == "r")
    flylog_output << "The years " << begin_year_str << " - " << ending_year_str << endl;
if (date_range_inq == "c")
    {
	flylog_output << date_format(begin_year_str, begin_date_str) << " thru ";
	flylog_output << date_format(ending_year_str, ending_date_str) << endl;
    }
flylog_output << "Flight data found    : ";
if (planes[0].getFlights() > .5)
	flylog_output << planes[0].getFirstDate() << " thru " << planes[0].getLastDate() << endl;
else
	flylog_output << "no flights found" << endl;
if (date_range_inq == "n" && plane_inq == "n" && airport_inq == "n")
	flylog_output << "Airplane(s)       all: " << setw(4) << seq_plane.size() << endl;
if ((date_range_inq != "n" || airport_inq == "y") && plane_inq == "n")
	flylog_output << "Airplane(s)     found: " << setw(4) << seq_plane.size() << endl;
if (plane_inq == "y")
    flylog_output << "Airplane     searched: " << plane_select << "  " << plane_model_select << endl;

if (date_range_inq == "n" && plane_inq == "n" && airport_inq == "n")
	flylog_output << "Airport(s)        all: " << setw(4) << seq_airports.size() << endl;
if ((date_range_inq != "n" || plane_inq == "y") && airport_inq == "n")
	flylog_output << "Airport(s)      found: " << setw(4) << seq_airports.size() << endl;
if (airport_inq == "y")
    flylog_output << "Airport      searched: " << airports[airport_index_select].name()
											   << ", " << airports[airport_index_select].suf() << endl;

flylog_output << "Flights         Total: " << fixed << setprecision(0) << setw(4) << planes[0].getFlights() << endl;
flylog_output << "                Local: " << setw(4) << total_local_flights << endl;
flylog_output << "         <50 miles XC: " << setw(4) << trips_xc49_flights << endl;
flylog_output << "         50+ miles XC: " << setw(4) << trips_xc50_flights << endl;
flylog_output << "Hours                : " << fixed << setprecision(1) << setw(6) << planes[0].dayHours() / 10 << endl << endl;

// end of common header
if (planes[0].flights() > .5)
{
flylog_output << "Logbook totals:" << endl << endl;
flylog_output << "   Total";

for (unsigned int t = 0; t < class_types.size(); t++)
    {
    if (class_types[t].getFlights() > 0)
        flylog_output << util::string_print_spacer(class_types[t].getType(), 8) << class_types[t].getType();  
    }
if (rg_hours > 0)
    flylog_output << "      RG";
if (hp_hours > 0)
    flylog_output << "  HiPerf";
if (tw_hours > 0)
    flylog_output << "    Tail";
flylog_output << endl;

flylog_output << setw(8) << planes[0].dayHours() / 10;

for (unsigned int t = 0; t < class_types.size(); t++)
    {
    if (class_types[t].getFlights() > 0)
        flylog_output << fixed << setprecision(1) << setw(8) << class_types[t].dayHours() / 10.0;  
    }
if (rg_hours > 0)
    flylog_output << setw(8) << rg_hours / 10.0;
if (hp_hours > 0)
    flylog_output << setw(8) << hp_hours / 10.0;
if (tw_hours > 0)
    flylog_output << setw(8) << tw_hours / 10.0;
flylog_output << endl << endl;
if (planes[0].nightHours() > .5)
	flylog_output << "   Night";
if (planes[0].ifr() > .5)
	flylog_output << "     IFR";
if (planes[0].gad() > .5)
	flylog_output << "     GAD";
if (planes[0].xc() > .5)
	flylog_output << "      XC";
if (planes[0].cfi() > .5)
	flylog_output << "     CFI";
if (planes[0].dual() > .5)
	flylog_output << "    Dual";
if (planes[0].pic() > .5)
	flylog_output << "     PIC";
if (planes[0].sic() > .5)
	flylog_output << "     SIC";
if (planes[0].safety() > .5)
	flylog_output << "  Safety";
flylog_output <<  endl;
if (planes[0].nightHours() > .5) 
	flylog_output << setw(8) << planes[0].nightHours() / 10;
if (planes[0].ifr() > .5)
	flylog_output << setw(8) << planes[0].ifr() / 10;
if (planes[0].gad() > .5)                
	flylog_output << setw(8) << planes[0].gad() / 10;
if (planes[0].getXc() > .5)
	flylog_output << setw(8) << planes[0].getXc() / 10;                
if (planes[0].cfi() > .5)
	flylog_output << setw(8) << planes[0].cfi() / 10;
if (planes[0].dual() > .5)
	flylog_output << setw(8) << planes[0].dual() / 10;                
if (planes[0].pic() > .5)
	flylog_output << setw(8) << planes[0].pic() / 10;
if (planes[0].sic() > .5)
	flylog_output << setw(8) << planes[0].sic() / 10;
if (planes[0].safety() > .5)
	flylog_output << setw(8) << planes[0].safety() / 10;
flylog_output << endl << endl << endl;

flylog_output << "8710 Airplane hours/landings:" << endl;
flylog_output << "                                 XC     XC     XC         Night  Night  Night   Night" << endl;
flylog_output << "  Total   Dual   Solo    PIC   Dual   Solo    PIC    IFR   Dual   Land    PIC PIC/Lnd" << endl;
flylog_output << setw(7) << setprecision(1)  
			  << setw(7) << EST_total /10 
			  << setw(7) << EST_dual /10 
			  << setw(7) << EST_solo /10 
			  << setw(7) << EST_pic /10 
			  << setw(7) << EST_xc_dual /10 
			  << setw(7) << EST_xc_solo /10 
			  << setw(7) << EST_xc_pic /10 
			  << setw(7) << EST_ifr /10 
			  << setw(7) << EST_night_dual /10 
			  << setw(7) << setprecision(0) << EST_night_land 
			  << setw(7) << setprecision(1)<< EST_night_pic /10
			  << setw(8) << setprecision(0)<< EST_night_land_pic << endl << endl;
if (EST_sim > .5)
	flylog_output << "   Simu" << setprecision(1) << setw(7) << EST_sim_dual /10 << "         excludes sim time as CFI  "  << setw(7) << EST_sim /10 << endl << endl;
if (planes[0].gad() > .5)
	flylog_output << "    GAD" << setprecision(1) << setw(7) << EST_gad_dual /10 << setw(42) << planes[0].gad() /10 << endl << endl;
flylog_output << endl;

flylog_output << "Model Summary:" << endl <<endl;
flylog_output << "Model    Flights   Total";
if (planes[0].nightHours() > .5)
	flylog_output << "   Night";
if (planes[0].ifr() > .5)
	flylog_output << "     IFR";
if (planes[0].gad() > .5)
	flylog_output << "     GAD";
if (planes[0].getXc() > .5)
	flylog_output << "      XC";
if (planes[0].cfi() > .5)
	flylog_output << "     CFI";
if (planes[0].dual() > .5)
	flylog_output << "    Dual";
if (planes[0].pic() > .5)
	flylog_output << "     PIC";
if (planes[0].sic() > .5)
	flylog_output << "     SIC";
if (planes[0].safety() > .5)
	flylog_output << "  Safety";
flylog_output << endl << endl;

for (unsigned int t = 0; t < class_types.size(); t++)
	{
	for (unsigned int m = 0; m < class_models.size(); m++) 
		{
	    if (class_types[t].getType() == class_models[m].getType() && class_models[m].getFlights() > 0)
	        {
		flylog_output << class_models[m].getModel();
		flylog_output << util::string_print_spacer(class_models[m].getModel(), 8);
	        flylog_output << setw(8) << setprecision(0) << class_models[m].getFlights();		
	        flylog_output << setw(8) << setprecision(1) << class_models[m].dayHours() / 10.0;
		if (planes[0].nightHours() > .5)
			flylog_output << setw(8) << class_models[m].nightHours() / 10.0;
		if (planes[0].ifr() > .5)
			flylog_output << setw(8) << class_models[m].ifr() / 10.0;
		if (planes[0].gad() > .5)
			flylog_output << setw(8) << class_models[m].gad() / 10.0;
		if (planes[0].xc() > .5)
			flylog_output << setw(8) << class_models[m].getXc() / 10.0;
		if (planes[0].cfi() > .5)
			flylog_output << setw(8) << class_models[m].cfi() / 10.0;
		if (planes[0].dual() > .5)
			flylog_output << setw(8) << class_models[m].dual() / 10.0;
		if (planes[0].pic() > .5)
			flylog_output << setw(8) << class_models[m].pic() / 10.0;
		if (planes[0].sic() > .5)
			flylog_output << setw(8) << class_models[m].sic() / 10.0;
		if (planes[0].safety() > .5)	
			flylog_output << setw(8) << class_models[m].safety() / 10.0;
		flylog_output << endl;
			}
		}
	}
flylog_output << endl;
flylog_output << "Aircraft Summary:" << endl <<endl;
flylog_output << "Model    Flights   Total";
if (planes[0].nightHours() > .5)
	flylog_output << "   Night";
if (planes[0].ifr() > .5)
	flylog_output << "     IFR";
if (planes[0].gad() > .5)
	flylog_output << "     GAD";
if (planes[0].getXc() > .5)
	flylog_output << "      XC";
if (planes[0].cfi() > .5)
	flylog_output << "     CFI";
if (planes[0].dual() > .5)
	flylog_output << "    Dual";
if (planes[0].pic() > .5)
	flylog_output << "     PIC";
if (planes[0].sic() > .5)
	flylog_output << "     SIC";
if (planes[0].safety() > .5)
	flylog_output << "  Safety";
flylog_output << endl << endl;
for (unsigned int t = 0; t < class_types.size(); t++)
	{
	for (unsigned int m = 0; m < class_models.size(); m++) 
		{
	    if (class_types[t].getType() == class_models[m].getType() && class_models[m].getFlights() > 0)
	        {
		    flylog_output << class_models[m].getModel();
			flylog_output << string_print_spacer(class_models[m].getModel(), 8);
			if (class_models[m].getNumPlanes() < 10000)
				flylog_output << endl;
			else
				{
				flylog_output << setw(8) << setprecision(0) << class_models[m].getFlights();
		        flylog_output << setw(8) << setprecision(1) << class_models[m].dayHours() / 10.0;

				if (planes[0].nightHours() > .5)	
					flylog_output << setw(8) << class_models[m].nightHours() / 10.0;
				if (planes[0].ifr() > .5)	
					flylog_output << setw(8) << class_models[m].ifr() / 10.0;
				if (planes[0].gad() > .5)
					flylog_output << setw(8) << class_models[m].gad() / 10.0;
				if (planes[0].getXc() > .5)
					flylog_output << setw(8) << class_models[m].getXc() / 10.0;
				if (planes[0].cfi() > .5)
					flylog_output << setw(8) << class_models[m].cfi() / 10.0;
				if (planes[0].dual() > .5)
					flylog_output << setw(8) << class_models[m].dual() / 10.0;
				if (planes[0].pic() > .5)
					flylog_output << setw(8) << class_models[m].pic() / 10.0;
				if (planes[0].sic() > .5)
					flylog_output << setw(8) << class_models[m].sic() / 10.0;
				if (planes[0].safety() > .5)
					flylog_output << setw(8) << class_models[m].safety() / 10.0;
				flylog_output << endl;
				}
			for (unsigned int c = 0; c < planes.size(); c++)
				{
				if (planes[c].getModel() == class_models[m].getModel() && planes[c].getFlights() > 0)
					{
					flylog_output << string_print_spacer(planes[c].callNumber(), 8) << planes[c].callNumber();
					flylog_output << setw(8) << setprecision(0) << planes[c].getFlights();
					flylog_output << setw(8) << setprecision(1) << planes[c].dayHours() / 10.0;
					if (planes[0].nightHours() > .5)
						flylog_output << setw(8) << planes[c].nightHours() / 10.0;
					if (planes[0].ifr() > .5)
						flylog_output << setw(8) << planes[c].ifr() / 10.0;
					if (planes[0].gad() > .5)
						flylog_output << setw(8) << planes[c].gad() / 10.0;
					if (planes[0].getXc() > .5)
						flylog_output << setw(8) << planes[c].getXc() / 10.0;
					if (planes[0].cfi() > .5)
						flylog_output << setw(8) << planes[c].cfi() / 10.0;
					if (planes[0].dual() > .5)
						flylog_output << setw(8) << planes[c].dual() / 10.0;
					if (planes[0].pic() > .5)
						flylog_output << setw(8) << planes[c].pic() / 10.0;
					if (planes[0].sic() > .5)
						flylog_output << setw(8) << planes[c].sic() / 10.0;
					if (planes[0].safety() > .5)
						flylog_output << setw(8) << planes[c].safety() / 10.0;
					flylog_output << endl;
					}	// planes > 0
				}		// planes search
				flylog_output << endl;
			}			// class_models > 0			
		}				// class_models search
	}					// type search
}
if (student_total_hours > .5)
	{
	flylog_output << endl << endl << "   First      Last    Flights   Hours    #  Students" << endl << endl;
	for (unsigned int i = 0; i < students.size(); i++)
        {
            if (students[i].dayHours() > .5)
                {
				flylog_output << students[i].getFirstDate() << "  ";
				if (students[i].getFirstDate() == students[i].getLastDate())
					flylog_output << "          ";
				else
					flylog_output << students[i].getLastDate() << "  ";
				flylog_output << fixed << setprecision(0) << setw(9) << students[i].getFlights();
                flylog_output << fixed << setprecision(1) << setw(8) << students[i].dayHours() / 10.0;
				flylog_output << setw(5) << i + 1;
                flylog_output << "  " << students[i].getLastName();
				flylog_output << ", ";
				flylog_output << students[i].getFirstName();
                flylog_output << endl;
                }
        }
    }
flylog_output.close(); 

//****  trips output

cout << "           trips" << endl;
double trips_most = 0;
int trips_most_int;
int trips_round = 0;
int trips_once = 0;
for(unsigned int xc_ind = 0; xc_ind < class_trips.size(); xc_ind++)
	{
    if (trips_most < class_trips[xc_ind].getFlights() + class_trips[xc_ind].getRevFlights())
        trips_most = class_trips[xc_ind].getFlights() + class_trips[xc_ind].getRevFlights();
	if (class_trips[xc_ind].getRevFlights() > .5)
		trips_round += 1;
	if (class_trips[xc_ind].getFlights() < 1.5 && class_trips[xc_ind].getRevFlights() < .5)
		trips_once += 1;
	}
trips_most_int = int(trips_most + .5); 
ofstream trips_output;
trips_output.open("output_trips_most.txt");
std::string header_line;
ifstream header_trips;                
header_trips.open("output_logbook.txt");                
for (int i = 1; i < 12; i++)
	{
	getline(header_trips, header_line);
	trips_output << header_line << endl;
	}
header_trips.close();

if (trips_xc49_flights + trips_xc50_flights  > .5) 
{
trips_output << "Different trips: " << setw(4) << class_trips.size() << endl;
trips_output << "Round trips    : " << setw(4) << trips_round << endl;
trips_output << "One-way trips  : " << setw(4) << class_trips.size() - trips_round << endl;
trips_output << "Once only trips: " << setw(4) << trips_once << endl << endl;
trips_output << "                                 Flights  Hours     Miles  Avg Hours  Avg Miles" << endl << endl;
if (trips_xc49_flights > .5)
	{
	trips_output << "Cross country data for <50 miles   ";
	trips_output << fixed << setprecision(0) << setw(5) << trips_xc49_flights;
	trips_output << fixed << setprecision(1) << setw(7) << trips_xc49_hours / 10.0;
	trips_output << fixed << setprecision(0) << setw(10) << trips_xc49_distance;
	trips_output << fixed << setprecision(1) << setw(11) << (trips_xc49_hours / 10.0) / trips_xc49_flights;
	trips_output << fixed << setprecision(1) << setw(11) << trips_xc49_distance / trips_xc49_flights;
	trips_output << endl;
	}
if (trips_xc50_flights > .5)
	{
	trips_output << "Cross country data for 50+ miles   ";
	trips_output << fixed << setprecision(0) << setw(5) << trips_xc50_flights;
	trips_output << fixed << setprecision(1) << setw(7) << trips_xc50_hours / 10.0;
	trips_output << fixed << setprecision(0) << setw(10) << trips_xc50_distance;
	trips_output << fixed << setprecision(1) << setw(11) << (trips_xc50_hours / 10.0) / trips_xc50_flights;
	trips_output << fixed << setprecision(1) << setw(11) << trips_xc50_distance / trips_xc50_flights;
	trips_output << endl;
	}
trips_output << endl;
trips_output << "Longest cross country: ";
trips_output << trips_longest_date << "  " << fixed << setprecision(0) << setw(5) << trips_longest;
trips_output << " miles  " << airports[trips_longest_dep].name() << " " << airports[trips_longest_dep].suf();
trips_output << " to "     << airports[trips_longest_des].name() << " " << airports[trips_longest_des].suf() << endl << endl; 
}

if (total_local_flights > .5)
{
trips_output << "Local flight data:" << endl << endl;
trips_output << "First     Last      Airport                         Flights  Hours  Average" << endl << endl;
 
for (unsigned int i = 0; i < seq_airports.size(); i++)
	{
	if (airports[seq_airports[i]].getLocalFlights() > 0)
		{
		trips_output << airports[seq_airports[i]].getLocalFirstDate() << "  ";
		if (airports[seq_airports[i]].getLocalFirstDate() == airports[seq_airports[i]].getLocalLastDate())
			trips_output << "          ";
		else
			trips_output << airports[seq_airports[i]].getLocalLastDate() << "  ";
		trips_output << airports[seq_airports[i]].name() << string_print_spacer(airports[seq_airports[i]].name(), 26);
		trips_output << string_print_spacer(airports[seq_airports[i]].suf(), 3) << airports[seq_airports[i]].suf();
		trips_output << fixed << setprecision(0) << setw(10) << airports[seq_airports[i]].getLocalFlights();
		trips_output << fixed << setprecision(1) << setw(7) << airports[seq_airports[i]].getLocalHours() / 10;
		trips_output << fixed << setprecision(1) << setw(9) << (airports[seq_airports[i]].getLocalHours() / 10)
															   / airports[seq_airports[i]].getLocalFlights();
		trips_output << endl;
		}
	}
trips_output << endl;
}
if (trips_xc49_flights + trips_xc50_flights > .5) 
{
trips_output << "Cross Country Round Trips Data:" << endl << endl;
trips_output << "First     Last      From                           To                              Miles  Flights  Hours  Average" << endl << endl;

for (int i = trips_most_int; i > 0; i--)
	{
	for (unsigned int j = 0; j < class_trips.size(); j++)
		{
		if (class_trips[j].getFlights() + class_trips[j].getRevFlights() == i && class_trips[j].getRevFlights() != 0)
			{
			trips_output << class_trips[j].getFirstDate() << "  ";
			if (class_trips[j].getFirstDate() == class_trips[j].getLastDate())
				trips_output << "          ";
			else
				trips_output << class_trips[j].getLastDate() << "  ";
			trips_output << airports[class_trips[j].getDep()].name() << string_print_spacer(airports[class_trips[j].getDep()].name(), 26);
			trips_output << airports[class_trips[j].getDep()].suf() << string_print_spacer(airports[class_trips[j].getDep()].suf(), 3) << "  ";
			trips_output << airports[class_trips[j].getDes()].name() << string_print_spacer(airports[class_trips[j].getDes()].name(), 26);
			trips_output << airports[class_trips[j].getDes()].suf() << string_print_spacer(airports[class_trips[j].getDes()].suf(), 3);
			trips_output << fixed << setprecision(0) << setw(8) << class_trips[j].getMiles();
			trips_output << fixed << setprecision(0) << setw(9) << class_trips[j].getFlights();
			trips_output << fixed << setprecision(1) << setw(8) << class_trips[j].dayHours() / 10;
			trips_output << fixed << setprecision(1) << setw(8) << (class_trips[j].dayHours() / 10) / class_trips[j].getFlights();
			trips_output << endl;
			trips_output << class_trips[j].getRevFirstDate() << "  ";
			if (class_trips[j].getRevFirstDate() == class_trips[j].getRevLastDate())
				trips_output << "          ";
			else
				trips_output << class_trips[j].getRevLastDate() << "  ";
			trips_output << airports[class_trips[j].getDes()].name() << string_print_spacer(airports[class_trips[j].getDes()].name(), 26);
			trips_output << airports[class_trips[j].getDes()].suf() << string_print_spacer(airports[class_trips[j].getDes()].suf(), 3) << "  ";
			trips_output << airports[class_trips[j].getDep()].name() << string_print_spacer(airports[class_trips[j].getDep()].name(), 26);
			trips_output << airports[class_trips[j].getDep()].suf() << string_print_spacer(airports[class_trips[j].getDep()].suf(), 3);
			trips_output << "        ";
			trips_output << fixed << setprecision(0) << setw(9) << class_trips[j].getRevFlights();
			trips_output << fixed << setprecision(1) << setw(8) << class_trips[j].getRevHours() / 10;
			trips_output << fixed << setprecision(1) << setw(8) << (class_trips[j].getRevHours() / 10) / class_trips[j].getRevFlights();
			trips_output << endl << endl;
			}
		}
	}
trips_output << endl;
trips_output << "Cross Country One-way Trips Data:" << endl << endl;
trips_output << "First     Last      From                           To                              Miles  Flights  Hours  Average" << endl << endl;
for (int i = trips_most_int; i > 0; i--)
	{
	for (unsigned int j = 0; j < class_trips.size(); j++)
		{
		if (class_trips[j].getFlights() + class_trips[j].getRevFlights() == i && class_trips[j].getRevFlights() == 0)
			{
			trips_output << class_trips[j].getFirstDate() << "  ";
			if (class_trips[j].getFirstDate() == class_trips[j].getLastDate())
				trips_output << "          ";
			else
				trips_output << class_trips[j].getLastDate() << "  ";
			trips_output << airports[class_trips[j].getDep()].name() << string_print_spacer(airports[class_trips[j].getDep()].name(), 26);
			trips_output << airports[class_trips[j].getDep()].suf() << string_print_spacer(airports[class_trips[j].getDep()].suf(), 3) << "  ";
			trips_output << airports[class_trips[j].getDes()].name() << string_print_spacer(airports[class_trips[j].getDes()].name(), 26);
			trips_output << airports[class_trips[j].getDes()].suf() << string_print_spacer(airports[class_trips[j].getDes()].suf(), 3);
			trips_output << fixed << setprecision(0) << setw(8) << class_trips[j].getMiles();
			trips_output << fixed << setprecision(0) << setw(9) << class_trips[j].getFlights();
			trips_output << fixed << setprecision(1) << setw(8) << class_trips[j].dayHours() / 10;
			trips_output << fixed << setprecision(1) << setw(8) << (class_trips[j].dayHours() / 10) / class_trips[j].getFlights();
			trips_output << endl << endl;
			}
		}
	}
}
trips_output.close();	

ofstream trips2_output;
trips2_output.open("output_trips_long.txt");
// std::string header_line;
ifstream header_trips2;                
header_trips2.open("output_logbook.txt");                
for (int i = 1; i < 12; i++)
	{
	getline(header_trips2, header_line);
	trips2_output << header_line << endl;
	}
header_trips2.close();

if (trips_xc49_flights + trips_xc50_flights > .5) 
{
trips2_output << "Different trips: " << setw(4) << class_trips.size() << endl;
trips2_output << "Round trips    : " << setw(4) << trips_round << endl;
trips2_output << "One-way trips  : " << setw(4) << class_trips.size() - trips_round << endl;
trips2_output << "Once only trips: " << setw(4) << trips_once << endl << endl;
trips2_output << "                                 Flights  Hours     Miles  Avg Hours  Avg Miles" << endl << endl;
if (trips_xc49_flights > .5)
	{
	trips2_output << "Cross country data for <50 miles   ";
	trips2_output << fixed << setprecision(0) << setw(5) << trips_xc49_flights;
	trips2_output << fixed << setprecision(1) << setw(7) << trips_xc49_hours / 10.0;
	trips2_output << fixed << setprecision(0) << setw(10) << trips_xc49_distance;
	trips2_output << fixed << setprecision(1) << setw(11) << (trips_xc49_hours / 10.0) / trips_xc49_flights;
	trips2_output << fixed << setprecision(1) << setw(11) << trips_xc49_distance / trips_xc49_flights;
	trips2_output << endl;
	}
if (trips_xc50_flights > .5)
	{
	trips2_output << "Cross country data for 50+ miles   ";
	trips2_output << fixed << setprecision(0) << setw(5) << trips_xc50_flights;
	trips2_output << fixed << setprecision(1) << setw(7) << trips_xc50_hours / 10.0;
	trips2_output << fixed << setprecision(0) << setw(10) << trips_xc50_distance;
	trips2_output << fixed << setprecision(1) << setw(11) << (trips_xc50_hours / 10.0) / trips_xc50_flights;
	trips2_output << fixed << setprecision(1) << setw(11) << trips_xc50_distance / trips_xc50_flights;
	trips2_output << endl;
	}
trips2_output << endl;
int trips_longest_int = int(trips_longest + .5);
trips2_output << "Cross Country Trips from longest to shortest:" << endl << endl;
trips2_output << "First     Last      From                           To                              Miles  Flights  Hours  Average" << endl << endl;

for (int i = trips_longest_int; i > 0; i--)
	{
	for (unsigned int j = 0; j < class_trips.size(); j++)
		{
		if (int(class_trips[j].getMiles() + .5) == i)
			{
			trips2_output << class_trips[j].getFirstDate() << "  ";
			if (class_trips[j].getFirstDate() == class_trips[j].getLastDate())
				trips2_output << "          ";
			else
				trips2_output << class_trips[j].getLastDate() << "  ";
			trips2_output << airports[class_trips[j].getDep()].name() << string_print_spacer(airports[class_trips[j].getDep()].name(), 26);
			trips2_output << airports[class_trips[j].getDep()].suf() << string_print_spacer(airports[class_trips[j].getDep()].suf(), 3) << "  ";
			trips2_output << airports[class_trips[j].getDes()].name() << string_print_spacer(airports[class_trips[j].getDes()].name(), 26);
			trips2_output << airports[class_trips[j].getDes()].suf() << string_print_spacer(airports[class_trips[j].getDes()].suf(), 3);
			trips2_output << fixed << setprecision(0) << setw(8) << class_trips[j].getMiles();
			trips2_output << fixed << setprecision(0) << setw(9) << class_trips[j].getFlights();
			trips2_output << fixed << setprecision(1) << setw(8) << class_trips[j].dayHours() / 10;
			trips2_output << fixed << setprecision(1) << setw(8) << (class_trips[j].dayHours() / 10) / class_trips[j].getFlights() << endl;;
			if (class_trips[j].getRevFlights() > .5)
				{
				trips2_output << class_trips[j].getRevFirstDate() << "  ";
				if (class_trips[j].getRevFirstDate() == class_trips[j].getRevLastDate())
					trips2_output << "          ";
				else
					trips2_output << class_trips[j].getRevLastDate() << "  ";
				trips2_output << airports[class_trips[j].getDes()].name() << string_print_spacer(airports[class_trips[j].getDes()].name(), 26);
				trips2_output << airports[class_trips[j].getDes()].suf() << string_print_spacer(airports[class_trips[j].getDes()].suf(), 3) << "  ";
				trips2_output << airports[class_trips[j].getDep()].name() << string_print_spacer(airports[class_trips[j].getDep()].name(), 26);
				trips2_output << airports[class_trips[j].getDep()].suf() << string_print_spacer(airports[class_trips[j].getDep()].suf(), 3);
				trips2_output << "        ";
				trips2_output << fixed << setprecision(0) << setw(9) << class_trips[j].getRevFlights();
				trips2_output << fixed << setprecision(1) << setw(8) << class_trips[j].getRevHours() / 10;
				trips2_output << fixed << setprecision(1) << setw(8) << (class_trips[j].getRevHours() / 10) / class_trips[j].getRevFlights() << endl;
				}
			trips2_output << endl;
			}
		}
	}
trips2_output << endl;
}
trips2_output.close();

// sequence output files

cout << "           sequence plane" << endl;
ofstream sequence_plane_output;                //  sequence plane output
sequence_plane_output.open("output_sequence_plane.txt");
ifstream header_seq_plane;                
header_seq_plane.open("output_logbook.txt");                
for (int i = 1; i < 12; i++)
{
	getline(header_seq_plane, header_line);
	sequence_plane_output << header_line << endl;
}

header_seq_plane.close();
if (planes[0].getFlights() > .5)
{						// end bracket 2784
	if (plane_inq == "n")
    {
		sequence_plane_output << "  #    CALL#   MODEL     FIRST      LAST   FLIGHTS   HOURS" << endl << endl;
		for (unsigned int r = 0; r < seq_plane.size(); r++)        
		{
			sequence_plane_output << setw(3) << r + 1;
			sequence_plane_output << " ";    
			sequence_plane_output << string_print_spacer (planes[seq_plane[r]].callNumber(), 8);
			sequence_plane_output << planes[seq_plane[r]].callNumber(); 
			sequence_plane_output << string_print_spacer (planes[seq_plane[r]].getModel(), 8);
			sequence_plane_output << planes[seq_plane[r]].getModel(); 
			sequence_plane_output << "  ";    
			sequence_plane_output << planes[seq_plane[r]].getFirstDate() << "  ";
			
			if (planes[seq_plane[r]].getFirstDate() == planes[seq_plane[r]].getLastDate())
				sequence_plane_output << "          ";
			else
				sequence_plane_output << planes[seq_plane[r]].getLastDate() << "  ";

			sequence_plane_output << fixed << setprecision(0) << setw(8) << planes[seq_plane[r]].getFlights();
			sequence_plane_output << fixed << setprecision(1) << setw(8) << planes[seq_plane[r]].dayHours() / 10 << endl;     
		}
    }

	if (plane_inq == "y")
	{
		if (airport_inq == "n")
			sequence_plane_output << endl << endl << "    Date  Hours  From                           To (blank if local)" << endl << endl;       
		else
			sequence_plane_output << endl << endl << "    Date  Hours     To/From   Blank if local" << endl << endl;
		
		for(unsigned int i = 0; i < seq_select.size(); i++)
		{
			sequence_plane_output << log[seq_select[i]].dateStr() << "  ";
			sequence_plane_output << fixed << setprecision(1) << setw(5) << log[seq_select[i]].dayHours() / 10.0 << "  ";
			if (airport_inq == "n")
			{        
				sequence_plane_output << airports[log[seq_select[i]].getDepInd()].name();
				sequence_plane_output << string_print_spacer(airports[log[seq_select[i]].getDepInd()].name(), 26) << "  ";
				sequence_plane_output << string_print_spacer(airports[log[seq_select[i]].getDepInd()].suf(), 3);
				sequence_plane_output << airports[log[seq_select[i]].getDepInd()].suf();

				if (log[seq_select[i]].getDepInd() != log[seq_select[i]].getDesInd())
				{
					sequence_plane_output << "  ";
					sequence_plane_output << airports[log[seq_select[i]].getDesInd()].name();
					sequence_plane_output << string_print_spacer(airports[log[seq_select[i]].getDesInd()].name(), 26) << "  ";
					sequence_plane_output << string_print_spacer(airports[log[seq_select[i]].getDesInd()].suf(), 3);
					sequence_plane_output << airports[log[seq_select[i]].getDesInd()].suf();
				}
				sequence_plane_output << endl;
			}
			else
			{
				if (log[seq_select[i]].getDepInd() == log[seq_select[i]].getDesInd())
				sequence_plane_output << endl;            
				else
				{
					if (log[seq_select[i]].getDepInd() == airport_index_select)
					{
						sequence_plane_output << "   to        ";
						sequence_plane_output << airports[log[seq_select[i]].getDesInd()].name();
						sequence_plane_output << string_print_spacer(airports[log[seq_select[i]].getDesInd()].name(), 26) << "  ";
						sequence_plane_output << string_print_spacer(airports[log[seq_select[i]].getDesInd()].suf(), 3);
						sequence_plane_output << airports[log[seq_select[i]].getDesInd()].suf() << endl;
					}
					else
					{ 
						sequence_plane_output << "      from   ";
						sequence_plane_output << airports[log[seq_select[i]].getDepInd()].name();
						sequence_plane_output << string_print_spacer(airports[log[seq_select[i]].getDepInd()].name(), 26) << "  ";
						sequence_plane_output << string_print_spacer(airports[log[seq_select[i]].getDepInd()].suf(), 3);
						sequence_plane_output << airports[log[seq_select[i]].getDepInd()].suf() << endl;
					}
				}    // to/from
			}        // else airport_inq = y
		}            // for loop to print inq list
	}                // if plane_inq = y
}					 // if flights > 0  start bracket 2711
sequence_plane_output.close();

std::cout << "sequence airport" << std::endl;
ofstream sequence_airport_output;            //  sequence airport output                
sequence_airport_output.open("output_sequence_airport.txt");
ifstream header_seq_airport;                
header_seq_airport.open("output_logbook.txt");                
for (int i = 1; i < 12; i++)
{
	getline(header_seq_airport, header_line);
	sequence_airport_output << header_line << endl;
}

header_seq_airport.close();

if (planes[0].getFlights() > .5)
{						//end bracket 2866
	if (airport_inq == "n")
    {
		sequence_airport_output << "                                                                 XC              Local "<< endl;
		sequence_airport_output << "   #    First      Last    ID   Airport                          Flights  Hours  Flights  Hours" << endl << endl;
		for (unsigned int p = 0; p < seq_airports.size(); p++)        
			{
			sequence_airport_output << setw(4) << p + 1;
			sequence_airport_output << " ";
			sequence_airport_output << airports[seq_airports[p]].getFirstDate() << "  ";
			if (airports[seq_airports[p]].getFirstDate() == airports[seq_airports[p]].getLastDate())
				sequence_airport_output << "          ";
			else
				sequence_airport_output << airports[seq_airports[p]].getLastDate() << "  ";
			sequence_airport_output << string_print_spacer (airports[seq_airports[p]].id(), 4);
			sequence_airport_output << airports[seq_airports[p]].id();
			sequence_airport_output << "   ";    
			sequence_airport_output << airports[seq_airports[p]].name() << string_print_spacer(airports[seq_airports[p]].name(), 26);
			sequence_airport_output << string_print_spacer(airports[seq_airports[p]].suf(), 3) << airports[seq_airports[p]].suf();
			sequence_airport_output << "   ";
			sequence_airport_output << fixed  << setprecision(0) << setw(8) << airports[seq_airports[p]].getXcFlights();
			sequence_airport_output << fixed  << setprecision(1) << setw(7) << airports[seq_airports[p]].getXcHours() / 10;
			if (airports[seq_airports[p]].getLocalFlights() > 0)
				{
				sequence_airport_output << fixed  << setprecision(0) << setw(9) << airports[seq_airports[p]].getLocalFlights();
				sequence_airport_output << fixed  << setprecision(1) << setw(7) << airports[seq_airports[p]].getLocalHours() / 10;
				}
			sequence_airport_output << endl;
			}
		}
	if (airport_inq == "y")
    {
		if (plane_inq == "n")
			sequence_airport_output << endl << endl << "    Date  Hours     Plane   Model   To/From   Blank if local" << endl << endl;       
		else
			sequence_airport_output << endl << endl << "    Date  Hours     To/From   Blank if local" << endl << endl;

		for(unsigned int i = 0; i < seq_select.size(); i++)
		{
			sequence_airport_output << log[seq_select[i]].dateStr() << "  ";
			sequence_airport_output << fixed << setprecision(1) << setw(5) << log[seq_select[i]].dayHours() / 10.0 << "  ";
			if (plane_inq == "n")
			{
				sequence_airport_output << string_print_spacer(planes[log[seq_select[i]].getPlaneInd()].callNumber(), 8);
				sequence_airport_output << planes[log[seq_select[i]].getPlaneInd()].callNumber();
				sequence_airport_output << string_print_spacer(planes[log[seq_select[i]].getPlaneInd()].getModel(), 8);
				sequence_airport_output << planes[log[seq_select[i]].getPlaneInd()].getModel();
			}
			if (log[seq_select[i]].getDepInd() == log[seq_select[i]].getDesInd())
				sequence_airport_output << endl;            
			else
			{
				if (log[seq_select[i]].getDepInd() == airport_index_select)
				{
					sequence_airport_output << "   to    ";
					sequence_airport_output << airports[log[seq_select[i]].getDesInd()].name();
					sequence_airport_output << string_print_spacer(airports[log[seq_select[i]].getDesInd()].name(), 26) << "  ";
					sequence_airport_output << string_print_spacer(airports[log[seq_select[i]].getDesInd()].suf(), 3);
					sequence_airport_output << airports[log[seq_select[i]].getDesInd()].suf() << endl;
				}
				else
				{ 
					sequence_airport_output << "   from   ";
					sequence_airport_output << airports[log[seq_select[i]].getDepInd()].name();
					sequence_airport_output << string_print_spacer(airports[log[seq_select[i]].getDepInd()].name(), 26) << "  ";
					sequence_airport_output << string_print_spacer(airports[log[seq_select[i]].getDepInd()].suf(), 3);
					sequence_airport_output << airports[log[seq_select[i]].getDepInd()].suf() << endl;
				}
			}
		}
    }
}				// if flights >0 start bracket 2799
sequence_airport_output.close();

// plotter processing
if (seq_airports.size() > 1)
{								// end bracket at 3041
std::cout << "           plotter" << std::endl;
double latmax = -90;            // set plotter variables
double latmin = 90;
double lonmax = -180;
double lonmin = 180;
for (unsigned int i = 0; i < seq_airports.size(); ++i)
{
	if (airports[seq_airports[i]].getLatitude() < latmin)
		latmin = airports[seq_airports[i]].getLatitude();

	if (airports[seq_airports[i]].getLatitude() > latmax)
		latmax = airports[seq_airports[i]].getLatitude();

	if (airports[seq_airports[i]].getLongitude() < lonmin)
		lonmin = airports[seq_airports[i]].getLongitude();

	if (airports[seq_airports[i]].getLongitude() > lonmax)
		lonmax = airports[seq_airports[i]].getLongitude();
}

double latmin_usa = 24.5;
double latmax_usa = 49.0;
double lonmin_usa = 68.33;
double lonmax_usa = 124.25;
double plot_lat_range_usa = 65;
double plot_lon_range_usa = 199;
int plot_lat_range_usa_int = 65;
int plot_lon_range_usa_int = 199;
double latmin_hi = 19.5;
double latmax_hi = 22.0;
double lonmin_hi = 155.0;
double lonmax_hi = 159.61;
double plot_lat_range_hi = 63;
double plot_lon_range_hi = 137;
int plot_lat_range_hi_int = 63;
int plot_lon_range_hi_int = 137;
double lat_range = latmax - latmin;
//if (lat_range < .5)	//prevents division by zero 4 statements below if only one airport found or chosen
//	lat_range = 1;
double lon_range = lonmax - lonmin;
double plot_lat_range = 65;
double plot_lon_range = (plot_lat_range * lon_range * 48.8 * cos(35 * (3.14159 / 180)) / (lat_range * 27));
int plot_lat_range_int = 65;
int plot_lon_range_int = int(plot_lon_range + .5);
//if (plot_lon_range_int < .5)  // prevents defining vector length < 1 if only one airport found or chosen
//	plot_lon_range_int = 1;

std::vector < int > usa_toland_row(199);
std::vector < std::vector < int > > table_usa_toland(65, usa_toland_row);
std::vector < int > usa_airports_row(199);
std::vector < std::vector < int > > table_usa_airports(65, usa_airports_row);
std::vector < std::string > usa_alpha_row(199);
std::vector < std::vector < std::string > > table_usa_alpha(65, usa_alpha_row);

for (int i = 0; i < 65; ++i)
{
	for (int j = 0; j < 199; ++j)
	{
		table_usa_toland[i][j] = 0;
		table_usa_airports[i][j] = 0;
		table_usa_alpha[i][j] = " ";
	}
}
std::vector< int > hi_toland_row(137);
std::vector< std::vector < int> > table_hi_toland(63, hi_toland_row);
std::vector< int > hi_airports_row(137);
std::vector< std::vector < int > > table_hi_airports(63, hi_airports_row);
std::vector< std::string > hi_alpha_row(137);
std::vector< std::vector< std::string > > table_hi_alpha(63, hi_alpha_row);

for (int i = 0; i < 63; ++i)
{
	for (int j = 0; j < 137; ++j)
	{
		table_hi_toland[i][j] = 0;
		table_hi_airports[i][j] = 0;
		table_hi_alpha[i][j] = " ";
	}
}

std::vector < int > all_toland_row(plot_lon_range_int);
std::vector < std::vector < int > > table_all_toland(65, all_toland_row);
std::vector < int > all_airports_row(plot_lon_range_int);
std::vector < std::vector < int > > table_all_airports(65, all_airports_row);
std::vector < std::string> all_alpha_row(plot_lon_range_int);
std::vector < std::vector < std::string > > table_all_alpha(65, all_alpha_row);

for(int i = 0; i < 65; i++)
	{
	for(int j = 0; j < plot_lon_range_int; j++)
		{
		table_all_toland[i][j] = 0;
		table_all_airports[i][j] = 0;
		table_all_alpha[i][j] = " ";
		}
	}
int x;
int y;
for (unsigned int i = 0; i < seq_airports.size(); i++)
    {
    if (airports[seq_airports[i]].getLatitude() > latmin_usa && airports[seq_airports[i]].getLatitude() < latmax_usa 
		&& airports[seq_airports[i]].getLongitude() > lonmin_usa && airports[seq_airports[i]].getLongitude() < lonmax_usa)  
        {
        x = plot_lat_range_usa_int - 1 - int((airports[seq_airports[i]].getLatitude() - latmin_usa) / (latmax_usa - latmin_usa) * (plot_lat_range_usa - 1));
        y = plot_lon_range_usa_int - 1 - int((airports[seq_airports[i]].getLongitude() - lonmin_usa) / (lonmax_usa - lonmin_usa) * (plot_lon_range_usa - 1));
		table_usa_toland[x][y] += int(airports[seq_airports[i]].getLocalFlights() + airports[seq_airports[i]].getXcFlights());
		table_usa_airports[x][y] += 1;
		if (table_usa_alpha[x][y] == " ")
			table_usa_alpha[x][y] = airports[seq_airports[i]].name().substr(0,1);
        }
    if (airports[seq_airports[i]].getLatitude() > latmin_hi && airports[seq_airports[i]].getLatitude() < latmax_hi 
		&& airports[seq_airports[i]].getLongitude() > lonmin_hi && airports[seq_airports[i]].getLongitude() < lonmax_hi)  
        {
        x = plot_lat_range_hi_int - 1 - int((airports[seq_airports[i]].getLatitude() - latmin_hi) / (latmax_hi - latmin_hi) * (plot_lat_range_hi - 1));
        y = plot_lon_range_hi_int - 1 - int((airports[seq_airports[i]].getLongitude() - lonmin_hi) / (lonmax_hi - lonmin_hi) * (plot_lon_range_hi - 1));
		table_hi_toland[x][y] += int(airports[seq_airports[i]].getLocalFlights() + airports[seq_airports[i]].getXcFlights());
		table_hi_airports[x][y] += 1;
		if (table_hi_alpha[x][y] == " ")
			table_hi_alpha[x][y] = airports[seq_airports[i]].name().substr(0,1);
        }
    x = plot_lat_range_int - 1 - int((airports[seq_airports[i]].getLatitude() - latmin) / (latmax - latmin) * (plot_lat_range - 1));
    y = plot_lon_range_int - 1 - int((airports[seq_airports[i]].getLongitude() - lonmin) / (lonmax - lonmin) * (plot_lon_range - 1));
	table_all_toland[x][y] += int(airports[seq_airports[i]].getLocalFlights() + airports[seq_airports[i]].getXcFlights());
	table_all_airports[x][y] += 1;
	if (table_all_alpha[x][y] == " ")
		table_all_alpha[x][y] = airports[seq_airports[i]].name().substr(0,1);
    }
ofstream usa_alpha_output;                            
usa_alpha_output.open("output_plotter_usa_alpha.txt");
ofstream usa_toland_output;                            
usa_toland_output.open("output_plotter_usa_toland.txt");
ofstream usa_airports_output;                            
usa_airports_output.open("output_plotter_usa_airports.txt");

for (int i = 0; i < 65; i++)
    {
    for (int j = 0; j < 199; j++)
        {
        if (table_usa_toland[i][j] == 0)
            usa_toland_output << " ";
        if (table_usa_toland[i][j] > 0 && table_usa_toland[i][j] < 10)
            usa_toland_output << setw(1) << table_usa_toland[i][j]; 
        if (table_usa_toland[i][j] > 9 && table_usa_toland[i][j] < 50)
            usa_toland_output << "X";
        if (table_usa_toland[i][j] > 49 && table_usa_toland[i][j] < 100)
            usa_toland_output << "L";
        if (table_usa_toland[i][j] > 99 && table_usa_toland[i][j] < 500)
            usa_toland_output << "C";            
        if (table_usa_toland[i][j] > 499 && table_usa_toland[i][j] < 1000)     
            usa_toland_output << "D";            
        if (table_usa_toland[i][j] > 999)     
            usa_toland_output << "M";
        if (table_usa_airports[i][j] == 0)
            usa_airports_output << " ";
        if (table_usa_airports[i][j] > 0 && table_usa_airports[i][j] < 10)
            usa_airports_output << setw(1) << table_usa_airports[i][j]; 
        if (table_usa_airports[i][j] > 9)
            usa_airports_output << "X";
		usa_alpha_output << table_usa_alpha[i][j];
        }
	usa_toland_output << endl;
	usa_airports_output << endl;
	usa_alpha_output << endl;
	}
usa_alpha_output.close();
usa_toland_output.close();
usa_airports_output.close();

ofstream hi_alpha_output;                            
hi_alpha_output.open("output_plotter_hi_alpha.txt");
ofstream hi_toland_output;                            
hi_toland_output.open("output_plotter_hi_toland.txt");
ofstream hi_airports_output;                            
hi_airports_output.open("output_plotter_hi_airports.txt");

for (int i = 0; i < 63; i++)
    {
    for (int j = 0; j < 137; j++)
        {
        if (table_hi_toland[i][j] == 0)
            hi_toland_output << " ";
        if (table_hi_toland[i][j] > 0 && table_hi_toland[i][j] < 10)
            hi_toland_output << setw(1) << table_hi_toland[i][j]; 
        if (table_hi_toland[i][j] > 9 && table_hi_toland[i][j] < 50)
            hi_toland_output << "X";
        if (table_hi_toland[i][j] > 49 && table_hi_toland[i][j] < 100)
            hi_toland_output << "L";
        if (table_hi_toland[i][j] > 99 && table_hi_toland[i][j] < 500)
            hi_toland_output << "C";            
        if (table_hi_toland[i][j] > 499 && table_hi_toland[i][j] < 1000)     
            hi_toland_output << "D";            
        if (table_hi_toland[i][j] > 999)     
            hi_toland_output << "M";
        if (table_hi_airports[i][j] == 0)
            hi_airports_output << " ";
        if (table_hi_airports[i][j] > 0 && table_hi_airports[i][j] < 10)
            hi_airports_output << setw(1) << table_hi_airports[i][j]; 
        if (table_hi_airports[i][j] > 9)
            hi_airports_output << "X";
		hi_alpha_output << table_hi_alpha[i][j];
        }
	hi_toland_output << endl;
	hi_airports_output << endl;
	hi_alpha_output << endl;
	}
hi_alpha_output.close();
hi_toland_output.close();
hi_airports_output.close();

ofstream all_alpha_output;                            
all_alpha_output.open("output_plotter_all_alpha.txt");
ofstream all_toland_output;                            
all_toland_output.open("output_plotter_all_toland.txt");
ofstream all_airports_output;                            
all_airports_output.open("output_plotter_all_airports.txt");

for (int i = 0; i < 65; i++)
    {
    for(int j = 0; j < plot_lon_range_int; j++)
        {
        if (table_all_toland[i][j] == 0)
            all_toland_output << " ";
        if (table_all_toland[i][j] > 0 && table_all_toland[i][j] < 10)
            all_toland_output << setw(1) << table_all_toland[i][j]; 
        if (table_all_toland[i][j] > 9 && table_all_toland[i][j] < 50)
            all_toland_output << "X";
        if (table_all_toland[i][j] > 49 && table_all_toland[i][j] < 100)
            all_toland_output << "L";
        if (table_all_toland[i][j] > 99 && table_all_toland[i][j] < 500)
            all_toland_output << "C";            
        if (table_all_toland[i][j] > 499 && table_all_toland[i][j] < 1000)     
            all_toland_output << "D";            
        if (table_all_toland[i][j] > 999)     
            all_toland_output << "M";
        if (table_all_airports[i][j] == 0)
            all_airports_output << " ";
        if (table_all_airports[i][j] > 0 && table_all_airports[i][j] < 10)
            all_airports_output << setw(1) << table_all_airports[i][j]; 
        if (table_all_airports[i][j] > 9)
            all_airports_output << "X";
		all_alpha_output << table_all_alpha[i][j];
        }
	all_toland_output << endl;
	all_airports_output << endl;
	all_alpha_output << endl;
	}
all_alpha_output.close();
all_toland_output.close();
all_airports_output.close();
}							// start bracket at 2871
	// output to the screen

	ifstream logbook_data;            
	logbook_data.open("output_logbook.txt");        

	if (logbook_data.fail())            
	{
		cout << "Bad flylog.txt file name";
		return -1;            
	}
	std::string logbook_data_line;    
	std::cout << std::endl  << std::endl;
	for (int i = 1; i < 19; i++)
	{
		getline(logbook_data, logbook_data_line);
		cout << logbook_data_line << endl;
		if (planes[0].getFlights() <.5 && i == 10)
			i = 19;
	}
	logbook_data.close();
	std::cout << std::endl << std::endl;


#pragma region currency checking
	// currency processing
	if (year_today == log[log.size() - 1].year() + 2)			
	{
		cout << "Your last flight was at least one year ago" << endl;
		cout << "You are not current for anything but solo VFR flight" << endl;
	}
	if (year_today > log[log.size() - 1].year() + 2)
	{
		cout << "Your last flight was at least " << year_today - log[log.size() -1].year() - 1 << " years ago" << endl;
		cout << "You are not current for anything. A BFR should be your next flight!" << endl;
	}

	if (year_today < log[log.size() -1 ].year() + 2)
	{
		// section to find dates of 90 and 180 day before today moved to top of program to allow for 90 and 180 
		// searches of flight data. Dates are used again in the currency section.

		// search the logbook backwards to check for the currencies

		int pass_landings = 0;
		int night_landings = 0;
		int appr = 0;
		std::string start_90 = "bad";
		std::string start_180 = "bad";
		vector<int> vec_pass_dates;
		vector<int> vec_pass_landings;
		int pass_curr_fl = -1;
		int pass_curr_year;
		vector<int> vec_night_dates;
		vector<int> vec_night_landings;
		int night_curr_fl = -1;
		int night_curr_year;
		vector<int> vec_appr_dates;
		vector<int> vec_appr_curr;
		int appr_curr_fl = -1;
		int appr_curr_year;

		for (int i = log.size() -1; i > -1; i--)
		{
			if (log[i].year() > year_start_90 || (log[i].year() == year_start_90 && log[i].date() > date_start_90))
			{
				if (log[i].getDayLand() + log[i].getNitLand() > 0)
				{
					pass_landings += (log[i].getDayLand() + log[i].getNitLand());
					vec_pass_landings.push_back(log[i].getDayLand() + log[i].getNitLand());
					vec_pass_dates.push_back(log[i].date());
					if (pass_landings > 2 && pass_curr_fl == -1)
					{
						pass_curr_fl = vec_pass_landings.size();
						pass_curr_year = log[i].year();
					}
				}
				if (log[i].getNitLand() > 0) 
				{
					night_landings += log[i].getNitLand();
					vec_night_landings.push_back(log[i].getNitLand());
					vec_night_dates.push_back(log[i].date());
					if (night_landings > 2 && night_curr_fl == -1)
					{
						night_curr_fl = vec_night_landings.size();
						night_curr_year = log[i].year();
					}
				}
			}
		} 

		for (int i = log.size() -1; i > -1; i--)
		{
			if (log[i].year() > year_start_180 || (log[i].year() == year_start_180 && log[i].date() > date_start_180))		
			{
				if (log[i].getAppr() > 0)
				{
					appr += log[i].getAppr();
					vec_appr_curr.push_back(log[i].getAppr());
					vec_appr_dates.push_back(log[i].date());
					if (appr > 5 && appr_curr_fl == -1)
					{
						appr_curr_fl = vec_appr_curr.size();
						appr_curr_year = log[i].year();
					}
				}
			}		
		}

	// assigns number of landings/approaches to one date if a single date appears multiple times
	// to clean up currency screen output

		for (int i = vec_pass_dates.size() - 2; i > -1;  i--)
		{
			if (vec_pass_dates[i] == vec_pass_dates[i+1])
			{
				vec_pass_landings[i] += vec_pass_landings[i+1];
				vec_pass_landings[i+1] = 0;
			}
		}

		for (int i = vec_night_dates.size() -2 ; i > -1 ; i--)
		{
			if (vec_night_dates[i] == vec_night_dates[i+1])
			{
				vec_night_landings[i] += vec_night_landings[i+1];
				vec_night_landings[i+1] = 0;
			}
		}

		for (int i = vec_appr_dates.size() - 2; i > -1; i--)
		{
			if (vec_appr_dates[i] == vec_appr_dates[i+1])
			{
				vec_appr_curr[i] += vec_appr_curr[i+1];
				vec_appr_curr[i+1] = 0;
			}
		}

		// find 90 and 180 day currency expiration dates
		int date_expire_90;
		int year_expire_90;
		int date_expire_180;
		int year_expire_180;
		int date_curr_comp;

		if (time_fun == "y" || time_fun == "y")
			cout << "Currencies as of today, ";
		else
			cout << "Currencies as of last logged flight, ";

		cout << int_to_string_date_format (year_today, date_today) << endl << endl;  

		if (pass_landings > 2)
		{
			cout << "Passenger  currency: GOOD  " << setw(2) << pass_landings << " landings   in last  90 days" << endl;
			cout << "Last three landings: ";
			for(int i = pass_curr_fl - 1; i > -1 ; i--)
			{
				if (vec_pass_landings[i] > 0)
				{
					cout << setw(2) << vec_pass_dates[i] / 100 << "/" << setw(2) << vec_pass_dates[i] % 100 << " ";
					if (vec_pass_landings[i] > 1)
						cout << "(" << vec_pass_landings[i] << ")  ";
				}
			}
			cout << endl;
			cout << "Currency expires on: ";
			date_curr_comp = (pass_curr_year % 4) * 10000 + vec_pass_dates[pass_curr_fl - 1];

			k = -1;			
			do
			{
				++k;
			} while(vec_dates[k] != date_curr_comp);

			date_expire_90 = vec_dates[k + 90] % 10000;
			if (vec_dates[k + 90] / 10000 == vec_dates[k] / 10000)
				year_expire_90 = pass_curr_year;
			else
				year_expire_90 = pass_curr_year + 1;
			cout << int_to_string_date_format (year_expire_90, date_expire_90) << endl << endl;
		}  
		else
		{
			cout << "Passenger  currency:  BAD  " << setw(2) << pass_landings << " landings   in last  90 days" << endl;
			if (vec_pass_landings.size() > 0)
			{
				cout << "Last landing  dates: ";
				for (int i = vec_pass_landings.size() - 1; i > -1; i--)
				{
					if (vec_pass_landings[i] > 0)
					{
						std::cout << setw(2) << vec_pass_dates[i] / 100 << "/" << setw(2) << vec_pass_dates[i] % 100 << " ";
						if (vec_pass_landings[i] > 1)
							cout << "(" << vec_pass_landings[i] << ")  ";
					}
				}
			}
			std::cout << std::endl << std::endl;
		}

		if (night_landings > 2)
		{
			cout << "Night currency: GOOD  " << setw(2) << night_landings << " landings   in last  90 days" << std::endl;
			cout << "Last three landings: ";
			for(int i = night_curr_fl - 1; i > -1 ; i--)
			{
				if (vec_night_landings[i] > 0)
				{
					cout << setw(2) << vec_night_dates[i] / 100 << "/" << setw(2) << vec_night_dates[i] % 100 << " ";
					if (vec_night_landings[i] > 1)
						cout << "(" << vec_night_landings[i] << ")  ";
				}
			}
			std::cout << std::endl;
			std::cout << "Currency expires on: ";

			date_curr_comp = (night_curr_year % 4) * 10000 + vec_night_dates[night_curr_fl - 1];
			k = -1;
			do
			{
				++k;
			} while(vec_dates[k] != date_curr_comp);

			date_expire_90 = vec_dates[k + 90] % 10000;

			if (vec_dates[k + 90] / 10000 == vec_dates[k] / 10000)
				year_expire_90 = night_curr_year;
			else
				year_expire_90 = night_curr_year + 1;
			std::cout << int_to_string_date_format (year_expire_90, date_expire_90) << std::endl << std::endl;
		}			
		else
		{
			std::cout << "Night      currency:  BAD  " << setw(2) << night_landings << " landings   in last  90 days" << std::endl;
			if (vec_night_landings.size() > 0)
			{			
				cout << "Last landing dates: ";
				for (int i = vec_night_landings.size() -1; i > -1; i--)
				{
					if (vec_night_landings[i] > 0)
					{
						cout << setw(2) << vec_night_dates[i] / 100 << "/" << setw(2) << vec_night_dates[i] % 100 << " ";
						if (vec_night_landings[i] > 1)
							cout << "(" << vec_night_landings[i] << ")  ";
					}
				}
			}
			cout << endl << endl;
		}

		if (appr > 5)
		{
			std::cout << "IFR        currency: GOOD  " << setw(2) << appr << " approaches in last 180 days" << std::endl;
			std::cout << "Last six approaches: ";
			for(int i = appr_curr_fl - 1; i > -1 ; i--)
				{
				if (vec_appr_curr[i] > 0)
					{
					std::cout << setw(2) << vec_appr_dates[i] / 100 << "/" << setw(2) << vec_appr_dates[i] % 100 << " ";
					if (vec_appr_curr[i] > 1)
						std::cout << "(" << vec_appr_curr[i] << ")  ";
					}
				}
			std::cout << std::endl;
			std::cout << "Currency expires on: ";
			date_curr_comp = (appr_curr_year % 4) * 10000 + vec_appr_dates[appr_curr_fl - 1];
			k = -1;
			do
			{
				++k;
			} while(vec_dates[k] != date_curr_comp);

			date_expire_180 = vec_dates[k + 180] % 10000;

			if (vec_dates[k + 180] / 10000 == vec_dates[k] / 10000)
				year_expire_180 = appr_curr_year;
			else
				year_expire_180 = appr_curr_year + 1;
			cout << int_to_string_date_format (year_expire_180, date_expire_180) << std::endl << std::endl;
		}
		else
		{
			std::cout << "IFR        currency:  BAD  " << setw(2) << appr << " approaches in last 180 days" << std::endl;
			if (vec_appr_curr.size() > 0)
			{			
				std::cout << "Last approach dates: ";
				for (int i = vec_appr_curr.size() -1; i > - 1; i--)
				{
					if (vec_appr_curr[i] > 0)
					{
						std::cout << setw(2) << vec_appr_dates[i] / 100 << "/" << setw(2) << vec_appr_dates[i] % 100 << " ";
						if (vec_appr_curr[i] > 1)
							std::cout << "(" << vec_appr_curr[i] << ")  ";
					}
				}
			}
			std::cout << std::endl;
		}
	}      //  year entry good to check for recurrency
#pragma endregion
#endif
